package com.sunfeng.a04;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
import org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver;
import org.springframework.context.support.GenericApplicationContext;

/**
 * @Author : 孙峰
 * @Description:
 * @Date : 2022/4/8  14:13
 */
@Slf4j
public class A04Application {
    public static void main(String[] args) {

        GenericApplicationContext context = new GenericApplicationContext();
        context.registerBean("bean1",Bean01.class);
        context.registerBean("bean2",Bean02.class);
        context.registerBean("bean3",Bean03.class);
        context.registerBean("bean4",Bean04.class);
        // 设置依赖注入的候选处理器
        context.getDefaultListableBeanFactory().setAutowireCandidateResolver(new ContextAnnotationAutowireCandidateResolver());


        context.registerBean(AutowiredAnnotationBeanPostProcessor.class);//  @Autowired  @Value

        context.registerBean(CommonAnnotationBeanPostProcessor.class);// @Resource   @PostConstruct @PreDestroy   这些都是Java自带的注解

        ConfigurationPropertiesBindingPostProcessor.register(context.getDefaultListableBeanFactory());// @ConfigurationProperties
        context.refresh();
        System.out.println(context.getBean(Bean04.class));
        context.close();
    }
}
